package calculus;

import calculus.function.*;
import calculus.function.exceptions.DeriveException;
import calculus.function.exceptions.InputException;
import calculus.function.exceptions.UndefinedVariableException;
import calculus.function.pieces.*;
import calculus.ui.*;

public class Program {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Ui calcInterface = new Ui();
		calcInterface.OpenWindow(); 
		Piece toGraph;
		while (true) {
			try {
				toGraph = calcInterface.getInput();
				break;
			}
			catch (InputException e) {
				System.out.println("Error: " + e.getMessage());
			}
			catch (UndefinedVariableException e) {
				System.out.println("Error: Undefined constant or variable " + e.VariableName());
			}
		}
		toGraph = toGraph.Simplify();
		System.out.println(toGraph.toString());
		SingleVarFunction svf = new SingleVarFunction(toGraph, "x");
		svf.ConsoleGraph(-10, 10, 1, -10, 10, 1);
		svf.SetBounds(-10, 10, .1);
		calcInterface.Graph2d(svf);
		try {
			Piece toGraphd = toGraph.Derive("x");
			System.out.println("Derrivative of given equation:");
			System.out.println(toGraphd.toString());
			System.out.println(toGraphd.Simplify().toString());
			SingleVarFunction svfd = new SingleVarFunction(toGraphd, "x");
			svfd.ConsoleGraph(-10, 10, 1, -10, 10, 1);
		} catch (DeriveException e) {
			e.printStackTrace();
		}
	}

}
